<?php
include './Classes/PHPExcel.php';
// $res = Db::table('think_image')->select();
$res = [
	['id' => 1, 'name' => 'Tem1', 'image' => '1.jpg'],
	['id' => 2, 'name' => 'Tem2', 'image' => '1.jpg'],
	['id' => 3, 'name' => 'Tem3', 'image' => '1.jpg'],
];
$resultPHPExcel = new PHPExcel();
//设置参数
$resultPHPExcel->getActiveSheet()->setCellValue('A1', 'id');
$resultPHPExcel->getActiveSheet()->setCellValue('B1', '名称');
$resultPHPExcel->getActiveSheet()->setCellValue('C1', '图片');
$i = 2;
foreach ($res as $item) {
	$resultPHPExcel->getActiveSheet()->setCellValue('A' . $i, $item['id']);
	$resultPHPExcel->getActiveSheet()->setCellValue('B' . $i, $item['name']);
	$objDrawing = new \PHPExcel_Worksheet_Drawing();
	$objDrawing->setPath($item['image']);//这里拼接 . 是因为要在根目录下获取
	// 设置宽度高度
	$objDrawing->setHeight(50);//照片高度
	$objDrawing->setWidth(50); //照片宽度
	/*设置图片要插入的单元格*/
	$objDrawing->setCoordinates('C' . $i);
	// 图片偏移距离
	$objDrawing->setOffsetX(0);
	$objDrawing->setOffsetY(0);
	$objDrawing->setWorksheet($resultPHPExcel->getActiveSheet());
	$i++;
}
//设置导出文件名
$outputFileName = 'total.xls';
$xlsWriter = new \PHPExcel_Writer_Excel5($resultPHPExcel);
ob_end_clean();
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
header('Content-Disposition:inline;filename="' . $outputFileName . '"');
header("Content-Transfer-Encoding: binary");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Pragma: no-cache");
$xlsWriter->save("php://output");
?>